import 'package:flutter/material.dart';
import 'package:flutter_app/chat/choose_chat.dart';

class CurrentTalkWidget extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return CurrentTalkState();
  }

}

class CurrentTalkState extends State{
  List<String> list;
  @override
  void initState() {
    super.initState();
    list = <String>[
      "123","456"
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: ListView(
        children: _getWidget(list)
      ),
    );
  }

  ///填充聊天列表
  List<Widget> _getWidget(List<String> list){
    List<Widget> widgets = <Widget>[];
    for(int i = 0; i < list.length; i++){
      widgets.add(GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: (){
          ChooseChat.startChat(context, list[i], false);
        },
        onLongPress: (){
          setState(() {
            list.removeAt(i);
          });
        },
        child: Container(
          margin: EdgeInsets.fromLTRB(12, 6, 12, 6),
          child: Row(
            children: <Widget>[
              Icon(Icons.person_outline,size: 48,),
              Column(
                children: <Widget>[
                  Text(list[i],style: TextStyle(fontSize: 24),),
                  Text("test")
                ],
              ),
              Expanded(child: Container()),
              Text(DateTime.now().hour.toString() + ":" + DateTime.now().minute.toString()),
            ],
          ),
        ),
      ));
      widgets.add(Divider(thickness: 1,height: 1,));
    }
    return widgets;
  }

}
